GameObject={}

GameObject.create = function(self, parent, plistname)
  print("create ", plistname)
  local go = {}
  setmetatable(go, GameObject)
  GameObject.__index = GameObject
  local sfc=CCSpriteFrameCache:sharedSpriteFrameCache()
  sfc:addSpriteFramesWithFile(string.format("%s.plist", plistname))
  local frame1=sfc:spriteFrameByName(string.format("%s_std_1.png", plistname))
  local frame2=sfc:spriteFrameByName(string.format("%s_att_1.png", plistname))
  local frame3=sfc:spriteFrameByName(string.format("%s_att_2.png", plistname))
  local frame4=sfc:spriteFrameByName(string.format("%s_att_3.png", plistname))

  local animation=CCAnimation:create()
  animation:addSpriteFrame(frame1)
  animation:addSpriteFrame(frame2)
  animation:addSpriteFrame(frame3)
  animation:addSpriteFrame(frame4)
  animation:setDelayPerUnit(0.4)

  local animate=CCAnimate:create(animation)
  --go.action = animate
  --go.sprite = CCSprite:createWithSpriteFrame(frame1)
  go.actions = {}
  go.compants = {}
  go.compants.normal = CCSprite:createWithSpriteFrame(frame1)
  go.normal = go.compants.normal
  go.actions.attack = animate
  

  go.actions.fireball = CCMoveBy:create(2, ccp(400,0))

  go.parent = parent
  parent:addChild(go.compants.normal)
  return go 
end

GameObject.setPosition = function(self, x, y)
  print(self)
  self.normal:setPosition(x,y)
end

GameObject.playActionDelayed = function(self, sprite, action, delay)
  local da=CCDelayTime:create(delay)
  local ca=CCCallFuncN:create(GameObject.onAttack)
  local arr=CCArray:create()
  arr:addObject(da)
  arr:addObject(action)
  arr:addObject(ca)
  print("GameObject.playActionDelayed ", da, action, ca)
  local sa=CCSequence:create(arr)
  sprite:runAction(sa)
  print("GameObject.playActionDelayed sprite ", sprite)
end

GameObject.onAttack = function(self)
  print("GameObject.onAttack")
  print(self)
end

--[[
ActionUtil.getAction = function(self, plistname)
  print("getAction ", plistname)
  local action = {}  
  local sfc=CCSpriteFrameCache:sharedSpriteFrameCache()
  sfc:addSpriteFramesWithFile(string.format("%s.plist", plistname))
  frame1=sfc:spriteFrameByName(string.format("%s_std_1.png", plistname))
  frame2=sfc:spriteFrameByName(string.format("%s_att_1.png", plistname))
  frame3=sfc:spriteFrameByName(string.format("%s_att_2.png", plistname))
  frame4=sfc:spriteFrameByName(string.format("%s_att_3.png", plistname))

  animation=CCAnimation:create()
  animation:addSpriteFrame(frame1)
  animation:addSpriteFrame(frame2)
  animation:addSpriteFrame(frame3)
  animation:addSpriteFrame(frame4)
  animation:setDelayPerUnit(0.4)

  animate=CCAnimate:create(animation)
  action.action = animate
  action.sprite = CCSprite:createWithSpriteFrame(frame1)
  return action
end
]]
--ActionUtil.getAction("a")
